#ifndef _Helper_H
#define _Helper_H

#include <iostream>


#ifndef PI
#define PI (3.14159265)
#endif

//Angle conversions
extern inline float degreesToRadians( float d)
{
	static const float pi_mult = PI / 180;
	return d * pi_mult;
}
extern inline float radiansToDegrees( float r)
{
	static const float pi_mult = 180 / PI;
	return r * pi_mult;
}



//A superfast square root implementation
extern float sqrtFast( float ) ;


/* linear interpolation */
extern inline float Lerp(float t, float a, float b)
{
	return( a + t * (b - a));
}



/** Templated Functions **/
//Safely delete a pointer
template <typename T>
void safeDelete(T *&ptr)
{
	if(ptr != NULL)
	{
		delete ptr;
		ptr = NULL;
	}else{
		std::cout << "[HELPER]->Tried to delete a NULL pointer" << std::endl;
	}
}//EoF



//Round a number to the degree you specify
template< typename T, const int Ndp >
T roundNumber( const T val )
{
	T raised  = pow( 10, (double)( abs(Ndp) ) );
	T temp 	 = val * raised;
	T rounded = static_cast<T>( floor( temp ) );

	if( temp - rounded >= (T)0.5 ) {
		rounded = static_cast<T>( ceil( temp ) );
	}

	return static_cast<T>(rounded / raised);
}



#endif